package com.jhy.new2025.array;

public class SearchInsert {
    public int searchInsert(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;

        while (left <= right) {
            int mid = left + (right-left)/2;
            int temp = nums[mid];
            if (target > temp) {
                left = mid + 1;
            } else if (target < temp) {
                right = mid - 1;
            } else {
                return mid;
            }
        }
        return left;
    }
}
